﻿using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata.Ecma335;

namespace Simple_search.ViewModels
{
    public class FinishSearchWindowViewModel : BindableBase, IDialogAware
    {
        public string Title { get; } = "检索完成";

        private string outputFilePath;
        public string OutputFilePath
        {
            get { return outputFilePath; }
            set { SetProperty(ref outputFilePath, value); }
        }

        private string text;
        public string Text
        {
            get { return text; }
            set { SetProperty(ref text, value); }
        }

        public event Action<IDialogResult> RequestClose;

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {
        }

        public void OnDialogOpened(IDialogParameters parameters)
        {
            string path = parameters.GetValue<string>("OutputFilePath");
            int resultCount = parameters.GetValue<int>("ResultCount");
            Text = string.Format("检索完成 共检索到 {0} 条", resultCount);
            OutputFilePath = string.Format("输出到 {0}", path);
        }

        private DelegateCommand commandClose;
        public DelegateCommand CommandClose =>
            commandClose ?? (commandClose = new DelegateCommand(ExecuteCommandClose));

        void ExecuteCommandClose()
        {
            RequestClose.Invoke(new DialogResult(ButtonResult.OK));
        }
    }
}
